<!--采购退货审核-->
<template>
  <div class="app-container">
    <div class="my-tabs">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="未审核" name="first">
        </el-tab-pane>
        <el-tab-pane label="审核不通过" name="second">
        </el-tab-pane>
        <el-tab-pane label="审核通过" name="third">
        </el-tab-pane>
      </el-tabs>
    </div>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="商品名称" align="center" prop="goodsName" width="400" :show-overflow-tooltip="true"/>
      <el-table-column label="退货原因" align="center" prop="returnReason" width="350" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag  :options="dict.type.return_reason" :value="scope.row.returnReason"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="退货描述" align="center" prop="reasonDesc" width="250" :show-overflow-tooltip="true"/>
      <el-table-column label="退货数量" align="center" prop="num" width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="应退金额" align="center" prop="amount" width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160" :show-overflow-tooltip="true">
         <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="activeName === 'first'"
                       width="180"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleRefund(scope.row,1)"
            >同意退货
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleSign(scope.row)"
            >拒绝
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listApproved,
  sign,
  refundAudit,
  toHandleList,
  handleList,
  shopReturnApproved, auditNoPass, auditPass
} from '@/api/store/purchaseReturn'
import Template from '@/views/setting/template/index.vue'

export default {
  name: 'Approved',
  components: { Template },
  dicts: ['sign_status', 'refund_status','return_reason'],
  data() {
    return {
      activeName: 'first',
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      dataList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        auditStatus:0
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleClick(tab, event) {
      this.queryParams.pageNum = 1
      switch (tab.name) {
        case 'first' :
          this.queryParams.auditStatus = 0
          this.getList()
          break
        case 'second' :
          this.queryParams.auditStatus = 1
          this.getList()
          break
        case 'third' :
          this.queryParams.auditStatus = 2
          this.getList()
          break
      }
    },
    /** 查询退货列表 */
    getList() {
      this.loading = true
      shopReturnApproved(this.queryParams).then(response => {
        this.dataList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 拒绝 */
    handleSign: function(row) {
      this.$confirm('是否拒绝退货！', '拒绝退货', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async() => {
        await auditNoPass({id:row.id})
        this.$modal.msgSuccess('成功拒绝退货')
        this.getList()
      }).catch(() => {
      })
    },
    /** 同意 */
    handleRefund: function(row) {
      this.$confirm('是否同意退货！', '同意退货', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async() => {
        await auditPass({id:row.id})
        this.$modal.msgSuccess('退货通过！')
        this.getList()
      }).catch(() => {

      })
    },
    // 查询退货原因
    queryReason(index){
      let arr = [
        { value: 0, text: 'Wrong product inform' },
        { value: 1, text: 'Address information error' },
        { value: 2, text: 'Too many pictures' },
        { value: 3, text: 'Consensus' },
        { value: 4, text: 'Out of stock' },
        { value: 5, text: 'Other' }
      ];
      let obj = arr.find(item => item.value === index)
      return obj.text || ''
    },
  }
}
</script>
